package de.clapp.newsfeed;

import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;
import de.clapp.R;
import de.clapp.data.Newsfeed;

public class NewsfeedFragment extends ListFragment
{
    private NewsfeedAdapter adapter;

    @Override
    public void onResume()
    {
        super.onResume();
        adapter = new NewsfeedAdapter(this);
        setListAdapter(adapter);
        setListShown(false);
        NewsfeedModel.getInstance().addListener(adapter);
    }

    @Override
    public void onPause()
    {
        NewsfeedModel.getInstance().removeListener(adapter);
        adapter = null;         
        super.onPause();
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id)
    {
        Newsfeed item = (Newsfeed) getListAdapter().getItem(position);
        Toast.makeText(getActivity(), getString(R.string.action_selected, item.getTitle()), Toast.LENGTH_SHORT).show();
        /*
         * Evtl. zum Club mit dieser News springen
         */
    }
}